package com.aaron.server;

import com.aaron.client.WorkspaceService;
import com.aaron.client.Workspace;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class WorkspaceServiceImpl extends RemoteServiceServlet implements
WorkspaceService{
	static final long serialVersionUID = 567890;
	public Workspace getWorkspace(String auth)throws Exception{
		try{
			SessionServer session_server=new SessionServer();
			if(session_server.confirmAndSync(auth)){
				String username=session_server.getUsername(auth);
				WorkspaceServer workspaceServer=new WorkspaceServer();
				//get all projects that have this username in them
				//create project proxies
				Workspace workspace=workspaceServer.getWorkspace(username);
				System.err.println ("getWorkspace: projects: "+workspace.getProjectProxies().size());
				return workspace;
			}
			else{
				System.err.println ("getWorkspace: Could not verify session: auth="+auth);
				throw new Exception("Could not login");
			}
		}
		catch(DatabaseException e){
			System.err.println ("getWorkspace: DatabaseException: "+e.getMessage());
			throw new Exception("Could not login");
		}
	}

}
